Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WM-27: [BE] 회원 생성 기능 #10

Open
wants to merge 2 commits into
base: wm-26
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/app/api/users/route.ts
Original file line number Diff line number Diff line change
@@ -12,3 +12,33 @@ export async function GET() {
return NextResponse.json({ error: 'Failed to fetch users' }, { status: 500 });
}
}

export async function POST(request: Request) {
const { db } = await get();
try {
const body = await request.json<CreateUserBody>();
const { email, name, profileUrl } = body;

if (!email) {
return NextResponse.json({ error: '이메일이 필요합니다' }, { status: 400 });
}

const user = await db.user.create({
data: {
email,
name,
profileUrl,
},
});

return NextResponse.json(user, { status: 201 });
} catch {
return NextResponse.json({ error: '유저 생성에 실패했습니다' }, { status: 500 });
}
}

type CreateUserBody = {
email: string;
name: string;
profileUrl: string;
};
6 changes: 5 additions & 1 deletion src/app/login/google/callback/page.tsx
Original file line number Diff line number Diff line change
@@ -48,7 +48,11 @@ export default function Page() {
});

if (!user) {
// TODO: 유저가 존재하지 않는 경우 유저 생성 로직 추가
await axios.post('/api/users', {
email: userEmail,
name: result.name,
profileUrl: result.picture,
});
}

// TODO: 세션/쿠키 설정하기 (로그인 처리)